#!/bin/bash

set -e

#npm run build

echo "rsync XXXXXX"
rsync -e 'ssh -p 51234' -avzIP --delete --exclude .git ./dist  root@47.100.185.138:/www/mobile/user/
rsync -e 'ssh -p 51234' -avzIP --delete --exclude .git Dockerfile  root@47.100.185.138:/www/mobile/user/
rsync -e 'ssh -p 51234' -avzIP --delete --exclude .git nginx.conf  root@47.100.185.138:/www/mobile/user/

ssh  -p 51234 root@47.100.185.138 'bash -se' <<'ENDSSH'
cd /www/mobile/user/
if docker build -t youzjhtml .
then
    echo "stop and rm old container,start new one..."
    docker stop youzjhtml
    docker rm youzjhtml
    docker run --restart=always --name  youzjhtml -d -p 7500:7500 youzjhtml
    docker ps
fi
ENDSSH


